home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d12
/
scd113.arc
/
DEMO2.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-06-14
|
4KB
|
121 lines
/*************************************************
** **
** demo2.c **
** **
** SoftC (tm) Dbase Library **
** Diskette TOC Demo Program **
** **
** Copyright (C) 1989 by **
** Kim Schumann **
** 16820 3rd St NE **
** Ham Lake, MN 55304 **
** (612) 434-6968 **
** **
** All rights reserved. **
*************************************************/
/*
The Diskette TOC Program is a simple program which will create a
database (TOC.DBF) and three index files. The database record
contains the following fields:
field name type length description
---------- ---- ------ -----------
NAME C 12 file name
LENGTH N 10.0 file size in bytes
DATE D 8 file creation date
TIME C 8 file creation time
ATTRIBUTE C 3 file attribute (READ ONLY, HIDDEN)
The index files created are: TOCNAME.NDX (file name),
TOCLNGTH.NDX (file length), and TOCDATE.NDX (file creation date
and time).
The program uses the DOS functions "findfirst" and "findnext" to
step through the files in the directory. It reformats the
compressed file date ("mm/dd/yy") and time ("hh:mm:ss") and
places the resultant data into the output buffer. After all
fields have been entered it will append a record to the end of
the database and add keys for each file found.
The program only works on the current directory. It does not
support any command line arguments, although it would be easy for
the user to add such support. Very little error checking is
performed.
The program as it stands has value only in the demonstration of
certain library functions. However, it could form the basis of a
diskette cataloger, or ...
*/
#include <stdlib.h>
#include <dir.h>
#include <stdio.h>
#include <string.h>
#include <sc_base.h>
SC_FIELD fields[] = { "name",'c',64,0,
"length",'n',10,0,
"date",'d',8,0,
"time",'c',8,0,
"attribute",'n',3,0 };
void main ()
{
struct ffblk ffblk;
int r, w1, w2, w3;
char dbf, ndx1, ndx2, ndx3, work[9], *key;
long recno;
double d;
scdinit(20);
scddcreate("toc.dbf",5,fields);
scddopen(&dbf,"toc.dbf");
scdncreate("tocname.ndx",'c',"name",64);
scdnopen(&ndx1,"tocname.ndx");
scdncreate("toclngth.ndx",'n',"length",64);
scdnopen(&ndx2,"toclngth.ndx");
scdncreate("tocdate.ndx",'c',"dtoc(date) + time",64);
scdnopen(&ndx3,"tocdate.ndx");
findfirst("*.*",&ffblk,0);
do {
scdfput(dbf,0,ffblk.ff_name);
d = (double) ffblk.ff_fsize;
scdfput(dbf,1,&d);
w1 = ((ffblk.ff_fdate & 0xFE00) >> 9) + 80;
w2 = (ffblk.ff_fdate & 0x01E0) >> 5;
w3 = ffblk.ff_fdate & 0x001F;
sprintf(work,"%02d/%02d/%02d",w2,w3,w1);
scdfput(dbf,2,work);
w1 = (ffblk.ff_ftime & 0xF800) >> 11;
w2 = (ffblk.ff_ftime & 0x07E0) >> 5;
w3 = (ffblk.ff_ftime & 0x001F) << 1;
sprintf(work,"%02d:%02d:%02d",w1,w2,w3);
scdfput(dbf,3,work);
d = (double) ffblk.ff_attrib;
scdfput(dbf,4,&d);
scdrput(dbf,&recno,SC_ADD);
if (sc_code == SC_SUCCESS)
scdkadd(ndx1,ffblk.ff_name,recno);
d = (double) ffblk.ff_fsize;
scdkadd(ndx2,(char *) &(d),recno);
scdkmake(dbf,ndx3,(void **) &key);
scdkadd(ndx3,key,recno);
free(key);
puts(ffblk.ff_name);
r = findnext(&ffblk);
} while (r != -1);
scddclose(dbf);
scdnclose(ndx1);
scdnclose(ndx2);
scdnclose(ndx3);
scdterm();
}